class Solution {
    public int minCost(int[][] costs) {
        int n=costs.length;
        int blue=0;
        int green=0;
        int red=0;

        blue=costs[0][1];
        red=costs[0][0];
        green=costs[0][2];


        for(int i=1;i<n;i++){
            int newred=costs[i][0]+Math.min(blue,green);
            int newblue=costs[i][1]+Math.min(green,red);
            int newgreen=costs[i][2]+Math.min(blue,red);

            red=newred;
            blue=newblue;
            green=newgreen;

        }

        return Math.min(red,Math.min(green,blue));

    }
}


class Solution1 {
    public int maxProfit(int[] prices) {
        int n=prices.length;


        int dp=-prices[0];
        int dp1=0;
        int dp2=0;

        for(int i=1;i<n;i++){


            int  newdp=Math.max(dp,dp1-prices[i]);
            int newdp1=Math.max(dp2,dp1);
            int newdp2=dp+prices[i];

            dp=newdp;
            dp1=newdp1;
            dp2=newdp2;
        }

        return Math.max(dp1,dp2);

    }
}